package com.ttbj.product.costsharing.imp;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ttbj.api.costsharing.CostSharingConfigService;
import com.ttbj.api.dto.CostSharingConfigDto;
import com.ttbj.api.exception.BusinessException;
import com.ttbj.constant.PlatFormErrorCode;
import com.ttbj.core.util.DtoTransitionUtils;
import com.ttbj.costsharing.bean.po.CostSharingConfig;
import com.ttbj.costsharing.dao.CostSharingConfigMapper;



@Service("costSharingConfigService")
public class CostSharingConfigImpl implements CostSharingConfigService{
	
	@Autowired
	private CostSharingConfigMapper costSharingManagerMapper;
	

	@Override
	public List<CostSharingConfigDto> findCostSharingConfigInfo() throws BusinessException {
		List<CostSharingConfig> costSharingConfigs = this.costSharingManagerMapper.queryCostSharingConfigInfo();
		List<CostSharingConfigDto> dtos = new ArrayList<>();
		for (CostSharingConfig costSharingManager : costSharingConfigs) {
			CostSharingConfigDto sDto = (CostSharingConfigDto) DtoTransitionUtils.trans(CostSharingConfigDto.class, costSharingManager);
			dtos.add(sDto);
		}
		return dtos;
	}

	
	@Override
	public void editCostSharingConfigInfo(CostSharingConfigDto costSharingConfigDto) throws BusinessException {
		CostSharingConfig costSharingManager = (CostSharingConfig) DtoTransitionUtils.trans(CostSharingConfig.class, costSharingConfigDto);
		//设置修改时间
		costSharingManager.setUpdateTime(new Date());
		int count = this.costSharingManagerMapper.updateCostSharingConfigInfo(costSharingManager);
		if (count == 0) {
			throw new BusinessException("修改失败，重新设置！", PlatFormErrorCode.DATA_SECURITY.code());
		}
	}

}
